package Metier;

import java.sql.SQLException;
import java.util.List;

import DAO.ContrainteDAO.ContrainteDAO;
import Factory.Factory;

public class ContraintePk {

	private String nomContrainte;
	private String nomTable;
	private List<String> listeAttributPk;
	
	private ContrainteDAO dao;
	
	public ContraintePk(String nomTable, String pK, List<String> listeAttributPk) {
		this.nomTable = nomTable;
		this.nomContrainte = pK;
		this.listeAttributPk = listeAttributPk;
		dao = Factory.getContrainteDAO();
	}
	public void add(String nomAttribut) {
		this.listeAttributPk.add(nomAttribut);
	}
	public void delete() throws SQLException {
		if (!this.nomContrainte.equals(""))
		dao.deleteConstraint(nomTable,nomContrainte);
	}
	public void save() throws SQLException {
		if (this.listeAttributPk.size()>0)
			dao.addPrimaryKey(nomTable, listeAttributPk);
	}
	public static ContraintePk GetContrainte(String nom) throws SQLException {
		return Factory.getContrainteDAO().getPrimaryKey(nom);
	}
	public void remove(String nomAttribut) {
		this.listeAttributPk.remove(nomAttribut);
	}
	

}
